/*
 * Copyright (c) 2020 Fraunhofer FOKUS and others. All rights reserved.
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contact: mosaic@fokus.fraunhofer.de
 */
package org.eclipse.mosaic.fed.sumo.traci.facades;

import org.eclipse.mosaic.fed.sumo.traci.TraciCommandException;
import org.eclipse.mosaic.fed.sumo.traci.TraciConnection;
import org.eclipse.mosaic.fed.sumo.traci.commands.EdgeGetIds;
import org.eclipse.mosaic.rti.api.InternalFederateException;

import java.util.List;

public class TraciEdgeFacade {

    private final TraciConnection traciConnection;

    private final EdgeGetIds edgeGetIds;

    /**
     * Constructor with TraCI connection.
     *
     * @param traciConnection connection for communicating with TraCI.
     */
    public TraciEdgeFacade(TraciConnection traciConnection) {
        this.traciConnection = traciConnection;

        this.edgeGetIds = traciConnection.getCommandRegister().getOrCreate(EdgeGetIds.class);
    }

    /**
     * Returns the list of edges.
     *
     * @return a list of edges
     * @throws InternalFederateException if getting the edges ids failed
     */
    public final List<String> getEdgeIdList() throws InternalFederateException {
        try {
            return edgeGetIds.execute(traciConnection);
        } catch (TraciCommandException e) {
            throw new InternalFederateException("Could not retrieve edges ids");
        }
    }
}
